<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Modelsphp
 *
 * @author C_NGA
 */
include_once '../config.php';
class Modelsphp {
    //put your code here
    public $db;
    public function __construct() {
       $this->db=  mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Không kết nối được CSDL');
       mysqli_set_charset($this->db, "utf8");
       }
    public function getAllUser()
    {
         $sql = "SELECT * FROM `tbd_user`";
        return mysqli_query($this->db, $sql);
    }
    public function getUserByName($name,$password)
    {
        $password=md5($password);
        $sql = "SELECT * FROM `tbd_user` where Name='$name' and Password='$password'";
        return mysqli_query($this->db, $sql);
    }
     public function addUser($name,$user,$pass,$def,$active)
    {
       /*  $name= trim($_POST['name']);
        $user= trim($_POST['username']);
        $pass=trim($_POST['password']);
        $def=$_POST['ckbdef']=='1'?1:0;
        $active=$_POST['ckbactive']=='1'?1:0;
        * 
        */
         if($def==1)
         {
             $pass=PASS_DEF;
         }
        $pass=md5($pass);
        
         $date=  date("Y-m-d");
         echo $date;
     
        $sql = "INSERT INTO `tbd_user`(`Name`, `UserName`, `Password`,`Active`, `EndAccess`) VALUES "
                . "('$name','$user','$pass','$active','$date')";
        mysqli_query($this->db, $sql) ;
       
    }
}
